﻿using System.IO;
using System.Text;

namespace WindowsFormsApplication1
{
    class GraphvizWriter
    {
        private StringBuilder SB = new StringBuilder();

        public GraphvizWriter(string name)
        {
            SB.AppendLine("digraph " + name.Trim().Replace(' ', '_')+"{");
            //System.Console.WriteLine("digraph " + name.Trim().Replace(' ', '_') + "{");
        }
        public GraphvizWriter(string name, string[] Options)
        {
            SB.AppendLine("digraph " + name.Trim().Replace(' ', '_') + "{");
            foreach (string option in Options)
            {
                SB.AppendLine("\t" + option + ";");
                //System.Console.WriteLine("\t" + option + ";");
            }
        }

        public void ConnNode(string From, string To)
        {
            SB.AppendLine(string.Format("\"{0}\" -> \"{1}\";",From,To));
            //System.Console.WriteLine(string.Format("\"{0}\" -> \"{1}\");", From, To));
        }
        public void ListNode(string ID, string Name, string style, string color, string shape)
        {
            SB.AppendLine(string.Format("\"{0}\" [ label=\"{1}\",shape=\"{2}\",style=\"{3}\",color=\"{4}\" ];", ID, Name, shape,style,color));
            //System.Console.WriteLine(string.Format("\"{0}\" [ label=\"{1}\",shape=\"{2}\",style=\"{3}\",color=\"{4}\" ];", ID, Name, shape, style, color));
        }

        public void SaveFile(string path)
        {
            SB.AppendLine("}");
            using (StreamWriter SW = new StreamWriter(path))
            {
                SW.Write(SB.ToString());
                System.Console.Write(SB.ToString());
            }
        }

    }
}
